//
//  YLMoreIntegralController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/19.
//  Copyright © 2017年 she1323. All rights reserved.
//  获取更多积分

#import "YLMoreIntegralController.h"
#import "YLMoreIntegralHeaderView.h"
#import "YLMoreIntergralTableViewCell.h"
#import "YLMoreIntergralViewModel.h"
#import "YLMoreIntegralHeaderView.h"
#import "YLMoreIntergralGroup.h"
@interface YLMoreIntegralController ()
@property (nonatomic, strong) YLMoreIntergralViewModel *viewModel;

@end

@implementation YLMoreIntegralController



- (YLMoreIntergralViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLMoreIntergralViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    

    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([YLMoreIntergralTableViewCell class]) bundle:nil] forCellReuseIdentifier:[YLMoreIntergralTableViewCell cellID]];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    __weak typeof(self) weakSelf = self;
    [[self.viewModel.requestCommand execute:nil] subscribeNext:^(id  _Nullable x) {
        [weakSelf.tableView reloadData];
    }];
}

- (instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.viewModel.groups.httpResult.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    YLMoreIntergralGroup *group = self.viewModel.groups.httpResult[section];
    return group.wayContent.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YLMoreIntergralTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[YLMoreIntergralTableViewCell cellID] forIndexPath:indexPath];
    //cell.model = self.viewModel.groups[indexPath.section].models[indexPath.row];
    YLMoreIntergralGroup *group = self.viewModel.groups.httpResult[indexPath.section];
    cell.showString = group.wayContent[indexPath.row];
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    YLMoreIntegralHeaderView *headerView = [[YLMoreIntegralHeaderView alloc] init];
    headerView.backgroundColor = [UIColor clearColor];
    YLMoreIntergralGroup *group = self.viewModel.groups.httpResult[section];
    headerView.title = group.wayTitle;
    headerView.iconName = group.iconName;
    return headerView;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 25;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 45;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 40;
}

@end
